<?php
include_once APPLICATION_PATH."/models/base/Agent_ProductBase.php";
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
class Model_Agent_Product extends Model_Agent_ProductBase{
    
}
class Model_Agent_ProductMapper extends Model_Agent_ProductMapperBase{
    public static function GetAgentProduct(){
        $db = Zend_Db_Table::getDefaultAdapter();
        $select= 'select agent_product.id,IFNULL(agent_product.quantity,0) as quantity,agent.status as status,agent.id as agent_id,IFNULL(agent_product.product_id,0) as product_id from agent left join agent_product on agent.id = agent_product.agent_id';
        $stmt=$db->query($select);
        $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $entries   = array();
        foreach ($rows as $row){
            $entry = new Model_Agent_Product();
            $entry->setId($row->id)
                ->setId($row->id)
                ->setProduct_Id($row->product_id)
                ->setAgent_Id($row->agent_id) 
                ->setQuantity($row->quantity)
                ->setStatus($row->status);
             $entries[] = $entry;
        }
        return $entries;
    }
    
    public function findbyid($agent_id,$product_id, Model_Agent_Product $entry){
        $db = Zend_Db_Table::getDefaultAdapter();
        $select= 'select * from agent_product where agent_id='.$agent_id.' and product_id='.$product_id.'';
        $stmt=$db->query($select);
        $row = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $entry->setId($row[0]->id)
                ->setId($row[0]->id)
                ->setAgent_Id($row[0]->agent_id)
                ->setCreated($row[0]->created)
                ->setCreated_By($row[0]->created_by)
                ->setModified($row[0]->modified)
                ->setModified_By($row[0]->modified_by)
                ->setOrder($row[0]->order)
                ->setStatus($row[0]->status)
                ->setProduct_Id($row[0]->product_id)
                ->setQuantity($row[0]->quantity);
    }
}
